package com.electric.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.electric.common.CommonStringUtils;
import com.electric.common.Contains;
import com.electric.common.LoggerInterface;
import com.electric.entity.RepairRecord;
import com.electric.mapper.RepairRecordMapper;
import com.electric.service.IRepairRecordStatisticsService;

/**
 * <p>
 * 故障记录 服务实现类
 * </p>
 *
 * @author zhangbin
 * @since 2018-08-28
 */
@Service
public class RepairRecordStatisticsServiceImpl extends ServiceImpl<RepairRecordMapper, RepairRecord> implements IRepairRecordStatisticsService,LoggerInterface {
	@Autowired
	private RepairRecordMapper recordRecordMapper;

	@Override
	public List<Map<String, Object>> statisticsCustomerPie(String startDate, String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerPie = recordRecordMapper.statisticsCustomerPie(params);
		return statisticsCustomerPie;
	}

	@Override
	public List<Map<String, Object>> statisticsVoltageLevelPie(String startDate, String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerPie = recordRecordMapper.statisticsVoltageLevelPie(params);
		return statisticsCustomerPie;
	}

	@Override
	public List<Map<String, Object>> statisticsRepairTypePie(String startDate, String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerPie = recordRecordMapper.statisticsRepairTypePie(params);
		return statisticsCustomerPie;
	}

	@Override
	public List<Map<String, Object>> statisticsVoltageLevelLine(String statisticsType, String startDate,
			String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		String FMT = CommonStringUtils.dayFmt2MysqlFmt(statisticsType);
		
		if(FMT != null) {
			params.put("FMT", FMT);
		}
		else {
			params.put("FMT", Contains.DAY_FMT_MYSQL);
		}
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerPie = recordRecordMapper.statisticsVoltageLevelLine(params);
		return statisticsCustomerPie;
	}

	@Override
	public List<Map<String, Object>> statisticsRepairTypeLine(String statisticsType, String startDate, String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		String FMT = CommonStringUtils.dayFmt2MysqlFmt(statisticsType);
		
		if(FMT != null) {
			params.put("FMT", FMT);
		}
		else {
			params.put("FMT", Contains.DAY_FMT_MYSQL);
		}
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerPie = recordRecordMapper.statisticsRepairTypeLine(params);
		return statisticsCustomerPie;
	}

	@Override
	public List<Map<String, Object>> statisticsCustomerVoltageLoss(String startDate, String endDate) {
		Map<String, Object> params = new HashMap<String,Object>();
		
		if(StringUtils.isNotBlank(startDate)) {
			params.put("startDate", startDate);
		}
		if(StringUtils.isNotBlank(endDate)) {
			params.put("endDate", endDate);
		}
		
		List<Map<String, Object>> statisticsCustomerVoltageLoss = recordRecordMapper.statisticsCustomerVoltageLoss(params);
		return statisticsCustomerVoltageLoss;
	}
}
